<?php

require_once '../lib.php';
$fp = new FP_Custom();

if (is_numeric($_REQUEST['uid'])) {
	$uid = $_REQUEST['uid'];
}
else if (isset($_REQUEST['uid'])) {
	preg_match('/id=(\d+)/', $_REQUEST['uid'], $matches);
	$uid = $matches[1];
}

$fp->uid = ($uid) ? $uid : $fp->get_app_developers(false);

try {
	$fp->get_info($fp->uid);

	$profile = trim($fp->facebook->api_client->profile_getFBML($fp->uid));
	$start = strpos($profile, '<fb:wide>') + 9;
	$end = strpos($profile, '</fb:wide>') - $start;
	$profile_fbml = substr($profile, $start, $end);

	$info = $fp->facebook->api_client->profile_getInfo($fp->uid);
}
catch (Exception $e) {
	
}

?>

<style>
h2.info { margin-top: 2em; margin-bottom: 1em; }
.overflow { overflow: auto; border: 1px solid #f7f7f7; }
.fixed { font-family: monospace; }
</style>

<fb:title>User Lookup</fb:title>
<link rel="stylesheet" type="text/css" media="screen" href="<?=$fp->callback_url?>/styles.php?v=<?=trim(REVISION)?>&amp;p=admin" />

<fb:if-is-user uid="<?=$fp->get_app_developers()?>">

	<div id="fp_header">
		<a href="http://apps.new.facebook.com/flickrsetsbeta/" title="Home"><img src="http://www.flickr.com/images/buddyicon.jpg" /></a>
		<h2>
			<a href="http://apps.new.facebook.com/flickrsetsbeta/" title="Home"><img src="<?=$fp->app_properties['icon_url']?>" /></a>
			<fb:application-name /> User Lookup
		</h2>
		<div class="headertabs"><div class="tabwrapper"><div class="thetabs">
			<a class="selected" href="<?=$fp->canvas_url?>/admin/lookup/">
				User Lookup
			</a>
			<a href="<?=$fp->canvas_url?>/admin/cache/">
				Cache Management
			</a>
		</div></div><div class="clearfix"></div></div>
		<form style="position: absolute; right: 0pt; bottom: 5pt;" method="post">
			<input type="text" name="uid" value="<?=$fp->uid?>" />
			<input type="submit" name="lookup" value="Lookup" />
		</form>
	</div>
	
	<div style="margin-top:29px;">
		
		<h1>Information for <fb:name uid="<?=$fp->uid?>" useyou="false" /></h1>
		
		<h2 class="info">Configuration Information</h2>
		<table border="1">
			<? foreach ($fp->config as $option => $value): ?>
			<tr>
				<td><?=$option?></td>
				<td><?=empty($value) ? '<i>NULL</i>' : $value ?></td>
			</tr>
			<? endforeach; ?>
		</table>
		
		<h2>Profile Box (Current)</h2>
		<? if (empty($profile)): ?>
			<p>Empty</p>
		<? else: ?>
			<div style="width:380px;">
				<?=$profile_fbml?>
			</div>
			<p><a href="" clicktotoggle="profile_fbml">Show/hide FBML</a>
				<div style="display:none;" class="overflow" id="profile_fbml">
					<pre>
						<?=htmlentities($profile)?>
					</pre>
				</div>
		<? endif; ?>
		
		<h2>Profile Box (Updated)</h2>
		<fb:iframe src="<?=$fp->callback_url?>/profile.php?handle=<?=$fp->uid?>" width="600" height="250" />
		
		<h2>Profile Info Box</h2>
		<div class="fixed">
			<?print_r($info)?>
		</div>
		
	</div>
<fb:else>
	<fb:error message="You're not allowed in here!" />
</fb:else>
</fb:if-is-user>